<script src="<?=base_url()?>templates/js/tabui.js" type="text/javascript"></script>
<script src="<?=base_url()?>templates/js/price_format.js" type="text/javascript"></script>
<script src="<?=base_url()?>templates/js/datetimepicker_css.js" type="text/javascript"></script>
<script type="text/javascript" src="<?=base_url()?>templates/js/jquery.formatCurrencyVN.js"></script>
<script src="<?=base_url()?>templates/js/price.js" type="text/javascript"></script>
<script language="javascript">    
jQuery(document).ready(function(){
    themanh();
	get_product_type();
});
function get_product_type()
{
	var filename = $("#kind").val() ;
	var ProductID = $("#ProductID").val() ;
	
	if(filename=='') return ;
	$("#producttype").html('<image src="'+url+'templates/images/loading.gif">');
    $.post(url+"ajax/loadformtype/" + filename + "/" + ProductID ,{},function(data)
    {
        $("#producttype").html(data);                                             
    });
}
</script>
<?=form_open('product/editproduct/'.$this->uri->segment(3),array('id'=>'adminformproduct'));?>

<input type="hidden" name="ProductID" id="ProductID" value="<?=$rs->ProductID?>">
<input type="hidden" value="detailed" id="selected_section" name="selected_section">
<div class="tabs cm-j-tabs cm-track">
   <ul>
      <li class="cm-js cm-active" id="detailed"><a>Tổng thể</a></li>
      <li class="cm-js" id="qty_discounts"><a>Giảm giá</a></li>
   </ul>
</div>
<div class="cm-tabs-content">
   <div id="content_detailed" class="hidden">
      <h2 class="subheader">Thông tin</h2>
      <table class="form" width="100%">
         <tr>
            <td class="required label">Tên sản phẩm</td>
            <td colspan="3"><input type="text" id="title" class=" max" name="ProductName" value="<?=$rs->ProductName?>"></td>
         </tr>
         <tr>
            <td class="required label">Giá M. Nam</td>
            <td width="257"><input type="text" class="w150" id="Price" name="Price" value="<?=format_price($rs->Price)?>" onblur="FPrice.set_priceHCM();" />
               <span id="Price_label"></span>
               <input name="VAT" type="checkbox" id="VAT" value="1" <? if($rs->VAT==1) echo 'checked="checked"'?> />
               VAT</td>
            <td>Giá khuyến mãi :
               <input type="text" class="w150" id="PriceCty" name="PriceCty" value="<?=format_price($rs->PriceCty)?>" onblur="FPrice.set_discountHCM()" /></td>
            <td>Giảm giá :
               <input type="text" class="w150" id="Discount" name="Discount" value="<?=($discount)?format_price($discount->DiscountNumber):'';?>" /></td>
         </tr>
         <tr>
            <td class="required label">Giá M. Bắc</td>
            <td><input type="text" class="w150" id="PriceHN" name="PriceHN" value="<?=format_price($rs->PriceHN)?>" onblur="FPrice.set_priceHN();" />
               <input name="VAT2" type="checkbox" id="VAT2" value="1" <? if($rs->VAT2==1) echo 'checked="checked"'?> />
               VAT</td>
            <td width="339">Giá khuyến mãi :
               <input type="text" class="w150" id="PriceHNPromo" name="PriceHNPromo" value="<?=format_price($rs->PriceHNPromo)?>" onblur="FPrice.set_discountHN()" /></td>
            <td width="481">Giảm giá :
               <input type="text" class="w150" id="DiscountHN" name="DiscountHN" value="<?=($discount)?format_price($discount->DiscountNumberHN):'';?>" /></td>
         </tr>
         <tr>
            <td class="required label">Nhà sản xuất</td>
            <td><select name="MenufactureID">
            		<option value="0">== không có ==</option>
                  <? foreach($menufacture as $row): ?>
                  <option value="<?=$row->MenufactureID?>" <?=($rs->MenufactureID == $row->MenufactureID)?'selected="selected"':'';?>>
                  <?=$row->MenufactureName?>
                  </option>
                  <? endforeach;?>
               </select></td>
            <td colspan="2"><label id="lbdate" style="color:#F00; font-weight:bold;"></label></td>
         </tr>
         <tr>
            <td class="required label">Nhóm sản phẩm</td>
            <td colspan="3"><select name="CategoryID">
                  <? foreach($listmaincat as $cat):
							 $listsub1 = $this->product->check_parentid($cat->CategoryID);
							 ?>
                  <option value="<?=$cat->CategoryID?>" <?=($cat->CategoryID == $rs->CategoryID)?'selected="selected"':'';?>><?=$cat->CategoryName?></option>
                  <? 
						if(count($listsub1) > 0){ 
							foreach($listsub1 as $sub1):
							 	$listsub2 = $this->product->check_parentid($sub1->CategoryID);
						?>
                  <option value="<?=$sub1->CategoryID?>" <?=($sub1->CategoryID == $rs->CategoryID)?'selected="selected"':'';?>>¦&nbsp;&nbsp;
                  <?=$cat->CategoryName?>&nbsp;¦&nbsp;<?=$sub1->CategoryName?>
                  </option>
                  <? if(count($listsub2) > 0){
								foreach($listsub2 as $sub2):?>
                           <option value="<?=$sub2->CategoryID?>" <?=($sub2->CategoryID == $rs->CategoryID)?'selected="selected"':'';?>>¦&nbsp;&nbsp;
                           <?=$cat->CategoryName?>
                           &nbsp;¦&nbsp;
                           <?=$sub1->CategoryName?>
                           ¦&nbsp;
                           <?=$sub2->CategoryName?>
                           </option>
                           <?  //start level 3
									$listsub3 = $this->product->check_parentid($sub2->CategoryID);
									if(count($listsub3) > 0){
											foreach($listsub3 as $sub3):?>
												<option value="<?=$sub3->CategoryID?>" <?=($sub3->CategoryID == $rs->CategoryID)?'selected="selected"':'';?>>¦&nbsp;&nbsp;
												<?=$cat->CategoryName?>
												&nbsp;¦&nbsp;
												<?=$sub1->CategoryName?>
												¦&nbsp;
												<?=$sub2->CategoryName?>
                                    ¦&nbsp;
												<?=$sub3->CategoryName?>
												</option>
										<? endforeach;?>
									<? } //end level 3 ?>
                  	<? endforeach;?>
                  <? } ?>
                  <? endforeach?>
                  <? }?>
                  <? endforeach;?>
               </select></td>
         </tr>
         <tr>
            <td class="label">Tính năng</td>
            <td colspan="3"><textarea id="wysiwyg-advanced" name="ProductFunc"><?=$rs->ProductFunc?>
</textarea></td>
         </tr>
         <tr>
            <td class="required label">Khuyến mãi</td>
            <td colspan="3"><input type="checkbox" name="IsHome" value="1" <?=($rs->IsHome==1)?'checked="checked"':'';?>></td>
         </tr>
         <tr>
            <td class="required label">Phạm vi</td>
            <td colspan="3"><input type="checkbox" name="IsHCM" id="IsHCM" value="1" <?=($rs->IsHCM==1)? 'checked="checked"':'';?> />
               Hồ Chí Minh
               &nbsp;&nbsp;&nbsp;
               <input type="checkbox" name="IsHN" id="IsHN" value="1" <?=($rs->IsHN==1)? 'checked="checked"':'';?> />
               Hà Nội</td>
         </tr>
         <tr>
            <td class="required label">Hiển thị</td>
            <td colspan="3"><input type="checkbox" name="IsActive" value="1" <?=($rs->IsActive==1)?'checked="checked"':'';?>></td>
         </tr>
      </table>
   </div>
   <div id="content_qty_discounts" class="hidden">
      <h2 class="subheader">Giảm giá</h2>
      <table width="100%" class="form">
         <tr>
            <td width="40%" class="label">Số tiền giảm giá (HCM)</td>
            <td width="60%"><input type="text" class="w150" id="DiscountNumber" name="DiscountNumber" value="<?=($discount)?format_price($discount->DiscountNumber):'';?>"></td>
         </tr>
         <tr>
            <td class="label">Số tiền giảm giá (HN)</td>
            <td><input type="text" class="w150" id="DiscountNumberHN" name="DiscountNumberHN" value="<?=($discount)?format_price($discount->DiscountNumberHN):'';?>" /></td>
         </tr>
         <tr>
            <td class="label">Khu vực</td>
            <td><input type="text" class="w150" id="DiscountArea" name="DiscountArea" value="<?=$discount->DiscountArea?>" /></td>
         </tr>
         <tr>
            <td class="label">Bắt đầu</td>
            <td><input type="text" class="w150" id="DiscountStartDate" name="DiscountStartDate" value="<?=($discount->DiscountStartDate!=0)?date('Y-m-d',$discount->DiscountStartDate):''?>"></td>
         </tr>
         <tr>
            <td class="label">Kết thúc</td>
            <td><input type="text" class="w150" id="DiscountEndDate" name="DiscountEndDate" value="<?=($discount->DiscountEndDate!=0)?date('Y-m-d',$discount->DiscountEndDate):''?>"></td>
         </tr>
      </table>
   </div>
</div>
<input type="submit" name="bt_submit" value="" class="capnhat">
<?=form_close();?>
<script type="text/javascript">
     $("#adminformproduct").validate({
        rules: {
            ProductName: "required",
            Alias: "required",
        },
        messages: {
            ProductName: "Vui lòng điền tên sản phẩm",
            Alias: "Mã trên link không được để trống.",
        }
    });
     
</script> 
<script>
    $(function() {
        var dates = $( "#DiscountStartDate, #DiscountEndDate" ).datepicker({

            changeMonth: true,
            dateFormat: 'yy-mm-dd', 
            numberOfMonths: 1,
            onSelect: function( selectedDate ) {
                var option = this.id == "DiscountStartDate" ? "minDate" : "maxDate",
                    instance = $( this ).data( "datepicker" );
                    date = $.datepicker.parseDate(
                        instance.settings.dateFormat ||
                        $.datepicker._defaults.dateFormat,
                        selectedDate, instance.settings );
                dates.not( this ).datepicker( "option", option, date );
            }
        });
    });
</script> 
<script type="text/javascript">
	$(function() {
		$(".delete_button").click(function(){
			if(confirm("Bạn có chắc chắn muốn xóa hình ảnh này\nĐồng ý chọn: OK\nHủy chọn: Cancel"))
			{
				var id = $(this).attr("id");
				var dataString = 'id='+ id ;
				var parent = $(this).parent();
				
				$.ajax({
						type: "POST",
						url: url+"product/delimg",
						data: dataString,
						cache: false,
						beforeSend: function(){
						parent.animate({'backgroundColor':'#fb6c6c'},300).animate({ opacity: 0.35 }, "past");;
					}, 
					success: function(){
					//parent.slideUp('slow', function() {$(this).remove();});
					}   
				});
			}
			return false;
		});
	 });
	 function chosen(id)
	 {
			if(id)
			{
				var vl = $('#v'+id).text();
				$('#ProductImg').val(vl);
				$('#main_img').html('<img src="' + urlimg + vl + '" width="85" height="85" />');
			}
			else
			{
				return false;
			}
	 }  
</script>